package com.bcu.cn.onlineexamsystem.user.mapper;

import com.bcu.cn.onlineexamsystem.user.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Param;

@Mapper
public interface UserMapper {
    @Select("SELECT * FROM users WHERE user_id = #{userId}")
    User selectUserById(String userId);

    // 新增注册方法
    @Insert("INSERT INTO users (user_id, user_name, password, role, email) " +
            "VALUES (#{userId}, #{userName}, #{password}, #{role}, #{email})")
    int insertUser(User user);

    // 更新邮箱和手机号
    @Update("UPDATE users SET email = #{email}, phone = #{phone} WHERE user_id = #{userId}")
    int updateContactInfo(@Param("userId") String userId, @Param("email") String email, @Param("phone") String phone);

    // 查询教师所授课程
    @Select("SELECT c.course_id, c.course_name FROM courses c JOIN teacher_courses tc ON c.course_id = tc.course_id WHERE tc.teacher_id = #{teacherId}")
    java.util.List<java.util.Map<String, Object>> findCoursesByTeacherId(@Param("teacherId") String teacherId);

    // 查询教师所带班级
    @Select("SELECT cl.class_id, cl.class_name FROM classes cl INNER JOIN teacher_classes tc ON cl.class_id = tc.class_id WHERE tc.teacher_id = #{teacherId}")
    java.util.List<java.util.Map<String, Object>> findClassesByTeacherId(@Param("teacherId") String teacherId);
}